package com.zysoft.common.service;

import java.lang.reflect.ParameterizedType;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.zysoft.common.dao.ICommonDao;
import com.zysoft.common.entity.AbstractEntity;

public abstract class BaseServiceImpl<M extends AbstractEntity, PK extends java.io.Serializable> implements IBaseService<M, PK> {
    protected static final Logger LOGGER = LoggerFactory.getLogger(BaseServiceImpl.class);

    @Autowired
    @Qualifier("CommonDao")
    protected ICommonDao commonDao;
    
    protected final Class<M> entityClass;

    @SuppressWarnings("unchecked")
    public BaseServiceImpl() {
        this.entityClass = (Class<M>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }
    
	@Override
	public M save(M model) {
		// TODO Auto-generated method stub
		return commonDao.save(model);
	}

	@Override
	public void saveOrUpdate(M model) {
		// TODO Auto-generated method stub
		commonDao.saveOrUpdate(model);
	}

	@Override
	public void update(M model) {
		// TODO Auto-generated method stub
		commonDao.update(model);
	}

	@Override
	public void merge(M model) {
		// TODO Auto-generated method stub
		commonDao.merge(model);
	}

	@Override
	public void delete(PK id) {
		// TODO Auto-generated method stub
		commonDao.delete(entityClass, id);
	}

	@Override
	public void deleteObject(M model) {
		// TODO Auto-generated method stub
		commonDao.deleteObject(model);
	}

	@Override
	public M get(PK id) {
		// TODO Auto-generated method stub
		return commonDao.get(entityClass, id);
	}

	@Override
	public long countAll() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<M> listAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public M unique() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public M unique(String where, Object... paramlist) {
		// TODO Auto-generated method stub
		return null;
	}

}
